package org.hrhr74.control.user;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.hrhr74.entity.*;
import org.hrhr74.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("Login")
@RequestMapping("/aidemo/user")
public class LoginController {
    @Resource
    private IUserService userService;

    /**
     * 手机验证码
     * **/
    @PostMapping("/code")
    public Result sendCode(@RequestParam("phone") String phone, HttpSession session){
        return userService.sendCode(phone,session);
    }
    /**
     * 登录-手机验证码
     */
    @PostMapping("/login_code")
    public Result login_code(@RequestBody LoginCode login, HttpSession session){
        return userService.login_code(login,session);
    }

    /**
     * 登录-账号密码
     * @param login
     * @param session
     * @return
     */
    @PostMapping("/login_pass")
    public Result login_password(@RequestBody LoginPassword login,HttpSession session){
        return userService.login_password(login,session);
    }

    /**
     * 修改用户信息（用户名、密码）
     * @param user
     * @return
     */
    @PutMapping("/update")
    public Result editUser(@RequestBody User user){
        return userService.editUser(user);
    }

    /**
     * 根据账号查询用户
     * @return
     */
    @GetMapping
    public Result getUser(){
        return userService.getUserByAccount();
    }

    /**
     * 换绑手机号
     * @return
     */
    @PutMapping("/update_phone")
    public Result updatePhone(@RequestBody UpdatePhone new_phone){
        return userService.updatePhone(new_phone);
    }
}
